package com.cloud.code.真题;

import java.io.IOException;

public class Demo25 {
    public static void main(String[] args) throws IOException {

        String str = "aaa_password_\"a12_45678\"_timeout__100_\"\"_";
        int index = 2;

        int count = 0;
        StringBuilder stringBuilder = new StringBuilder();
        while (str.length() > 0) {
            if (str.startsWith("_")) {
                str = str.substring(1);
                continue;
            }
            int index1 = str.indexOf("\"");
            int index2 = str.indexOf("_");
            if (index1 > index2 || index1 == -1 && index2 != -1) {
                if (count == index) {
                    stringBuilder.append("******_");
                } else {
                    stringBuilder.append(str.substring(0, index2) + "_");
                }
                str = str.substring(index2);
            } else if(index1 != -1) {
                String tem = str.substring(1);
                int index3 = tem.indexOf("\"");
                if (count == index) {
                    stringBuilder.append("******_");
                } else {
                    stringBuilder.append(str.substring(index1, index3+2));

                }
                str = str.substring(index3+2);
            }else {
                stringBuilder.append(str);
                str = "";
            }
            count++;

        }

        System.out.println(stringBuilder);


    }
}